from rest_framework.serializers import ModelSerializer, SerializerMethodField
from component import models


class ComponentSerializer(ModelSerializer):
    render = SerializerMethodField()
    type = SerializerMethodField()

    def get_render(self, obj):
        return obj.component_render_type.name

    def get_type(self, obj):
        return obj.component_type.name

    class Meta:
        model = models.Component
        fields = ['id', 'name', 'config', 'render', 'type']
